﻿using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Administration;

namespace SPDesigner.Policy
{
    public class SPDAdminJobFeatureReceiver:SPFeatureReceiver
    {
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            var webapp = properties.Feature.Parent as SPWebApplication;

           
            // Install the job.
            var spdj = new SPDAdminJobPermanent(webapp);

            SPDailySchedule schedule = new SPDailySchedule();
            schedule.BeginHour = 1;
            schedule.EndHour = 6;
            spdj.Schedule = schedule;

            spdj.Update();
        }


        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            var webapp = properties.Feature.Parent as SPWebApplication;

            // Delete the job.
            foreach (SPJobDefinition job in webapp.JobDefinitions)
            {
                if (job.Name == Globals.JobNamePermanent)
                    job.Delete();
            }

        }

        public override void FeatureInstalled(SPFeatureReceiverProperties properties)
        {
           
        }

        public override void FeatureUninstalling(SPFeatureReceiverProperties properties)
        {
           
        }
    }
}
